<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="servlets.message.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.UserMethods"%>


<script>
$("a.users").click(function() {
		$("#friends_content").hide().fadeIn(1000).load("friends/userProfile.jsp?user_id="+ $(this).attr('id'));
		return false;
	});
</script>


<div class="page-header">
	<h2 class="page-title">Twoi znajomi</h2>
</div>

<br />

<div id="content">

<%
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						RelationMethods  rm = new RelationMethods();
						 Integer user_id = (Integer) session.getAttribute("user_id");
							response.setContentType("text/html");
							if (user_id != null) {
						List<User> friendlist = rm.listAllFriends(sessionFactory, s, user_id);
						
						
					%> 
		
<%
		if (friendlist.size() > 0) {
	for (User f : friendlist) {
		int friend_user_id = f.getUser_id();
		String friend_username = f.getUsername();
		%>
		
		<div class="col-sm-4 col-md-4 user-details">
            <div class="user-image">
                <img src="http://www.gravatar.com/avatar/2ab7b2009d27ec37bffee791819a090c?s=100&d=mm&r=g" alt="Karan Singh Sisodia" title="Karan Singh Sisodia" class="img-circle">
            </div>
            <div class="user-info-block" >
                <div class="user-heading">
                    <h3><% out.println("<a class=\"users\" id=\""+ friend_user_id + "\" href=\"#\">" + friend_username + "</a>"); %> </h3>
                    <span class="help-block">Cos tam cos tam</span>
                </div>
</div>
<form action="../RelationDelete" method="POST" name='form1'>
			<input type="hidden" name="user_id" id="user_id" value="<%=user_id %>" />
			<%out.println("<input type=\"hidden\" name=\"check\" id=\"check\" value=\"" +friend_user_id +"\">" );%>
			<input type="submit" class="mainBtn" value="Usuń" />
</form>
</div>


		<%
		}
		} else out.println("Nie masz jeszcze zadnych znajomych");
			
		}
		s.getTransaction().commit();
		%>
	


</div>
